
import bpy
import sys
import os
import importlib

# --- Bulletproof Library Loading Block ---
try:
    # STEP 1: Define and VERIFY the path.
    library_path = '[?lib]'
    
    print(f"Attempting to load libraries from path: '{library_path}'")

    # STEP 2: Check if the path actually exists BEFORE trying to import.
    if not os.path.isdir(library_path):
        # This gives a clear, human-readable error.
        raise FileNotFoundError(f"The library path does not exist or is not a folder.")

    # STEP 3: Add the path and import the libraries.
    if library_path not in sys.path:
        sys.path.append(library_path)

    import Library
    import user_library
    
    importlib.reload(Library)
    importlib.reload(user_library)

    from Library import *
    from user_library import *
    
    print("--- Libraries successfully loaded for Text Editor script. ---")

except Exception as e:
    # This block now prints the error AND STOPS THE SCRIPT.
    print("--- SCRIPT HALTED DUE TO LIBRARY IMPORT ERROR ---")
    print(f"The original error was: {e}")
    # The 'raise' command re-throws the original error and gives you the full traceback.
    raise

# --- YOUR SCRIPT'S LOGIC STARTS HERE ---
